package at.sysarch.filter;

import java.awt.Rectangle;
import java.awt.image.RenderedImage;

import javax.media.jai.PlanarImage;

import at.pimpmypipe.filter.DataEnrichmentFilter;
import at.sysarch.bean.AbstractBean;
import at.sysarch.domain.TransferImage;

public class ROIFilter extends
		DataEnrichmentFilter<TransferImage, TransferImage> {

	private Rectangle _rectangle  = new Rectangle(0, 50, 448, 60);
	
	public ROIFilter(AbstractBean<ROIFilter> bean) {
		super(bean);
	}

	@Override
	protected boolean fillEntity(TransferImage nextVal, TransferImage entity) {

		PlanarImage image = PlanarImage
				.wrapRenderedImage((RenderedImage) nextVal.getModifiedImage()
						.getAsBufferedImage(_rectangle,
								nextVal.getModifiedImage().getColorModel()));
		entity.setModifiedImage(image);
		entity.setSourceImage(nextVal.getSourceImage());
		_bean.displayImage(entity);
		return true;
	}

	@Override
	protected TransferImage getNewEntityObject() {
		return new TransferImage();
	}

	public Rectangle getRectangle() {
		return _rectangle;
	}

	public void setRectangle(Rectangle rectangle) {
		_rectangle = rectangle;
	}

}
